package com.link.base.base.approval.controller;

import com.link.base.base.approval.model.ApprovalNode;
import com.link.base.base.approval.service.ApprovalNodeService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Copyright  hande Company. All Rights Reserved.
 *
 * @author unknwon
 * @version 1.0
 * @date: 2018/11/8 14:26
 */

@Controller
@RequestMapping("/link/approvalNode")
public class ApprovalNodeController extends BasicController<ApprovalNode> {

    @Resource
    private ApprovalNodeService approvalNodeService;

    @Override
    public BasicService<ApprovalNode> getBasicService() throws Exception {
        return approvalNodeService;
    }

    /**
     * 预处理：存在父子级联，所以强制父Id不能为空
     *
     * @param record
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/queryNodeOne", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public Map<String, Object> queryNodeOne(@JsonParam ApprovalNode record, HttpServletRequest request, HttpServletResponse response) {
        LCLogger.info().withMessageKey("queryNodeOne").withMessage("根据ID查询审批流程信息... ID:" + record.getId()).flush();
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            ApprovalNode approvalNode = approvalNodeService.queryOneApprovalNode(record);
            result.put("success", true);
            result.put("result", approvalNode);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.toString());
        }
        return result;
    }

}
